package com.xxbb.chapter_10.base_frame;

import java.awt.*;

import javax.swing.*;

public class BaseJFrame extends JFrame {
	private static Integer WINDOW_WIDTH = 800;
	private static Integer WINDOW_HEIGHT = 600;
	private static String WINDOW_TITLE = "基本窗口";
	private static Integer ScreenWidth = 0;
	private static Integer ScreenHeight = 0;
	// 窗口单列
	private static BaseJFrame instance = new BaseJFrame();

	public static BaseJFrame getInstance() {
		return instance;
	}

	// 获取屏幕宽高
	public BaseJFrame GetScreenInfo() {
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		// 获取屏幕宽度
		Dimension screenSize = toolkit.getScreenSize();
		ScreenWidth = screenSize.width;
		ScreenHeight = screenSize.height;
		return this;
	}

	// 设置窗口属性
	private void SetWindow() {
		// 设置窗口大小
		setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
		// 设置标题
		setTitle(WINDOW_TITLE);
	}
	//无参构造
	public BaseJFrame() {
		SetWindow();
	}

	// 有参数构造函数
	public BaseJFrame(Integer width, Integer height, String title) {
		WINDOW_WIDTH = width;
		WINDOW_HEIGHT = height;
		WINDOW_TITLE = title;
		SetWindow();
	}

	// 居中窗口
	public BaseJFrame setCenterWindow() {
		// 获取屏幕信息
		GetScreenInfo();
		// 设置居中
		Integer x = (ScreenWidth - WINDOW_WIDTH) / 2;
		Integer y = (ScreenHeight - WINDOW_HEIGHT) / 2;
		setLocation(x, y);
		return this;

	}

	// 展示窗口
	public BaseJFrame showWindow() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
		return this;
	}
	//面板JPanel
	public JPanel createJPanel() {
		JPanel panel=new JPanel();
		return panel;
	}
	//获取自带的JPanel
	public JPanel getThisJPanel(){
		return (JPanel)getContentPane();
	}
	//设置内容
	public BaseJFrame setJPanel(Component component){
		getContentPane().add(component);
		return this;
	}

	// 关闭当前窗口
	public BaseJFrame disposeWindow() {
		dispose();// 关闭
		return this;
	}

	// 关闭进程
	public BaseJFrame exitThis() {
		//Exit(0);
		return this;
	}

	// 是否可以改变大小
	public BaseJFrame setResizableWindow(Boolean resizeable) {
		setResizable(resizeable);
		return this;
	}
}
